/*hofNcN6oqI/ZPhij9Ckde28QLuBr0MVgOpGYH9g7rv/t5HS6jS2fzy1HfLyXQH4z*/
/*
 * @Author: xiahui 
 * @PageInfo: 列表工具 
 * @Date: 2019-01-18 09:54:45 
 * @Last Modified by: huoyzh
 * @Last Modified time: 2020-05-18 15:38:24
 */
import { AREA, FIELDS } from '../constance';
import { buttonControl } from '../list/viewControl/buttonControl';
import { listSingleTolerateForCompare } from '../../pub/utils/compareUtil';

/**
 * 差异更新列表界面
 * @param {*} props 
 * @param {*} data 
 * @param {*} listParam 
 * @param {*} config 
 */
function setListCompareData(props, data, listParam, config) {
	let { checkArr, record, index } = listParam;
	let updateData = [];
	if (record && index >= 0) {
		// 列表单行操作差异容错
		listSingleTolerateForCompare(data, record, config);
		// 行操作
		updateData.push({
			index: index,
			data: { values: data.head.head.rows[0].values }
		});
	} else if (checkArr && checkArr.length == 1) {
		// 按钮操作，一行数据
		let checkRow = checkArr[0];
		// 列表单行操作差异容错
		listSingleTolerateForCompare(data, checkRow.data.values, config);
		updateData.push({
			index: checkRow.index,
			data: { values: data.head.head.rows[0].values }
		});
	} else {
		// 按钮操作，多行数据
		data.head.rows.map((row) => {
			let pk = row.values[FIELDS.pk_ct_pu].value;
			checkArr.some((checkRow) => {
				if (
					pk == checkRow.data.values[FIELDS.pk_ct_pu].value ||
					pk == checkRow.data.values['pk_origct'].value
				) {
					updateData.push({
						index: checkRow.index,
						data: { values: row.values }
					});
					return true;
				}
			});
		});
	}
	props.table.updateDataByIndexs(AREA.listTableId, updateData);
	// 更新列表按钮状态
	buttonControl(props, props.table.getCheckedRows(AREA.listTableId));
}

export { setListCompareData };

/*hofNcN6oqI/ZPhij9Ckde28QLuBr0MVgOpGYH9g7rv/t5HS6jS2fzy1HfLyXQH4z*/